import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hotfil_pub_web/pages/home/widgets/text_form_bg_field.dart';
import 'package:hotfil_pub_web/service/loggin.dart';
import 'package:hotfil_pub_web/widgets/gradient_button.dart';
import 'package:hotfil_pub_web/widgets/webview_demo.dart';
import 'package:velocity_x/velocity_x.dart';

class PassLogin extends StatefulWidget {
  @override
  State<PassLogin> createState() => _PassLoginState();
}

class _PassLoginState extends State<PassLogin> {
  final _passlogin_form_key = GlobalKey<FormState>();

  String countryCode = '';

  String password = '';

  String phone = '';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(),
      body: Padding(
        padding: const EdgeInsets.only(top: 30, left: 24, right: 24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('账号密码登录'),
            Container(
              height: 200,
              child: WebviewDemo(),
            ),
            SizedBox(
              height: 50,
            ),
            Form(
                key: _passlogin_form_key,
                child: Column(
                  children: [
                    BgInput(
                      initialValue: '86',
                      hintText: '请输入手机国际区号',
                      validator: (val) {
                        if (val == null || val.isEmpty) {
                          return '手机国际区号不能为空';
                        } else {
                          return null;
                        }
                      },
                      keyboardType: TextInputType.phone,
                      onSaved: (_countryCode) {
                        countryCode = _countryCode!;
                      },
                    ),
                    18.heightBox,
                    BgInput(
                      initialValue: '18150935593',
                      hintText: '请输入手机号码',
                      keyboardType: TextInputType.phone,
                      onSaved: (_phone) {
                        phone = _phone!;
                      },
                    ),
                    18.heightBox,
                    BgInput(
                      initialValue: 'asd111111',
                      hintText: '请输入密码',
                      keyboardType: TextInputType.visiblePassword,
                      obscureText: true,
                      onSaved: (_password) {
                        password = _password!;
                      },
                    ),
                  ],
                )),
            54.heightBox,
            GradientButton(
              onPressed: () async {
                if (_passlogin_form_key.currentState!.validate()) {
                  // Process data.

                  _passlogin_form_key.currentState!.save();
                  passLoginApi(
                      countryCode: countryCode,
                      phone: phone,
                      password: password);
                } else {
                  print('不通过');
                }
              },
              text: '登录',
              disabled: false,
            )
          ],
        ),
      ),
    );
  }
}
